<style scoped>
    .el-checkbox{margin-top: 5px;}
</style>
<template>
    <div class="planned-distribution-page">
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            <el-tab-pane label="按计划汇总" name="first">
                <el-form :inline="true" :model="queryForm" ref="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
                    <el-form-item label="法人名称" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.legalPersonName" v-if="legalPersonLists.length == 1" disabled placeholder=""></el-input>
                        <el-select size="mini" v-model="queryForm.legalPersonName" v-else clearable @change="selectLegalPersonName"
                                placeholder="请选择">
                            <el-option v-for="(legalPerson,index) in legalPersonLists" :key="index" :label="legalPerson.legalPersonName"
                                    :value="legalPerson.legalPersonName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="计划汇总号" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.no" placeholder="请输入计划汇总号"></el-input>
                    </el-form-item>
                    <el-form-item label="汇总日期" class="selectMB10">
                        <el-date-picker type="date" size="mini" :editable="false" v-model="queryForm.createTimeStart" placeholder="请选择" @change="selectedCreateTimeStart"></el-date-picker>
                        &nbsp;至&nbsp;
                        <el-date-picker type="date" size="mini" :editable="false" v-model="queryForm.createTimeEnd" placeholder="请选择" @change="selectedCreateTimeEnd"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划汇总人" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.creatorName" placeholder="请输入人员账号"></el-input>
                    </el-form-item>
                    <el-checkbox v-model="queryForm.show">包括“未采购数量”为“0”的汇总计划</el-checkbox>
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryByPlan(activeName)">查询
                        </el-button>
                    </el-form-item>
                </el-form>
                <label class="default-label">计划汇总列表：</label>
                <el-table :data="byPlanTableData" border style="width: 100%;" v-loading.body="loading"
                          element-loading-text="拼命加载中">
                    <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                    <el-table-column label="操作" header-align="center" align="center" width="100" v-if="powerFlag2">
                        <template scope="scope">  <!--   -->
                            <div class="operationItem bolder">
                                <router-link :to="{ path: 'SummaryDetails', query: { planAggregationId: scope.row.id,no:scope.row.no}}" class="operationItem bolder">继续开单</router-link>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="createTime" label="汇总日期" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="creatorName" label="汇总人员" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="no" label="计划汇总号" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="totalQuantity" label="计划总数量" header-align="center" width="80">
                        <template scope="scope">
                            <el-button size="mini" @click="planQuantity(scope.$index, scope.row)"  class="blueFont">
                                {{scope.row.totalQuantity}}
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column prop="amount" label="已采购数量" header-align="center">
                        <template scope="scope">
                            <el-button size="mini" @click="byPlanQuantityPurchased(scope.$index, scope.row)"  class="blueFont">
                                {{scope.row.amount}}
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column prop="quantityNotPurchased" label="未采购数量" header-align="center" width="120"></el-table-column>
                </el-table>
                <!--分页-->
                <el-pagination v-if="isPaging1" @size-change="handleByPlanSizeChange" @current-change="handleByPlanCurrentChange" :current-page="byPlanPageIndex"  :page-size="byPlanPageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="byPlanTtotalPage" :total="byPlanTotalNumber"></el-pagination>
            </el-tab-pane>
            <el-tab-pane label="按备件汇总" name="second">
                <el-form :inline="true" :model="queryForm" ref="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
                    <el-form-item label="法人名称" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.legalPersonName" v-if="legalPersonLists.length == 1" disabled placeholder=""></el-input>
                        <el-select size="mini" v-model="queryForm.legalPersonName" v-else clearable @change="selectLegalPersonName"
                                placeholder="请选择">
                            <el-option v-for="(legalPerson,index) in legalPersonLists" :key="index" :label="legalPerson.legalPersonName"
                                    :value="legalPerson.id">
                            </el-option>
                        </el-select>
                        
                    </el-form-item>
                    <el-form-item label="计划汇总号" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.no" placeholder="请输入计划汇总号"></el-input>
                    </el-form-item>
                    <el-form-item label="汇总日期" class="selectMB10">
                        <el-date-picker type="date" size="mini" :editable="false" v-model="queryForm.createTimeStart"  placeholder="请选择" @change="selectedCreateTimeStart"></el-date-picker>
                        至
                        <el-date-picker type="date" size="mini" :editable="false" v-model="queryForm.createTimeEnd"  placeholder="请选择" @change="selectedCreateTimeEnd"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划汇总人" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.creatorName" placeholder="请输入人员账号"></el-input>
                    </el-form-item>
                    <el-form-item label="备件编码" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.materialCode" placeholder="请输入备件编码"></el-input>
                    </el-form-item>
                    <el-form-item label="备件名称" class="selectMB10">
                        <el-input size="mini" v-model="queryForm.materialName" placeholder="请输入备件名称"></el-input>
                    </el-form-item>
                    <el-checkbox v-model="queryForm.show">包括“未采购数量”为“0”的汇总计划
                    </el-checkbox>
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS selectAll" :disabled="select2Disabled" size="mini" type="danger" @click="queryBySpare(activeName)">查询
                        </el-button>
                    </el-form-item>
                </el-form>
                <label class="default-label">计划汇总列表：</label>
                <el-table :data="queryBySpareTable" border style="width: 100%;"
                          v-loading.body="loading2"
                          element-loading-text="拼命加载中">
                    <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                    <el-table-column label="操作" header-align="center" align="center" width="100" v-if="powerFlag2">
                        <template scope="scope">
                            <div class="operationItem bolder" @click="openSystemPO(scope.row)">开制PO</div>
                            <!--<el-button type="danger" class="bolder" size="mini" @click="openSystemPO(scope.row)">
                                开制PO
                            </el-button>
                             <router-link :to="{ path: 'SummaryDetails', query: { planAggregationId: scope.row.id}}"></router-link> -->
                        </template>
                    </el-table-column>
                    <el-table-column prop="no" label="计划汇总号" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="vendorName" label="供应商名称" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="materialCode" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="standard" label="规格" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="unit" label="计量单位" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="quantity" label="计划数量" header-align="center" width="80">
                        <template scope="scope">
                            <el-button size="mini" @click="planQuantity(scope.$index, scope.row)" class="blueFont">{{scope.row.quantity}}</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column prop="quantityNotPurchased" label="未采购数量" header-align="center" width="80"></el-table-column>
                    <el-table-column prop="amount" label="已采购数量" header-align="center" width="80">
                        <template scope="scope">
                            <el-button size="mini" @click="bySpareQuantityPurchased(scope.$index, scope.row)"  class="blueFont">{{scope.row.amount}}</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!--分页-->
                <el-pagination v-if="isPaging2" @size-change="handleBySpareSizeChange" @current-change="handleBySpareCurrentChange" :current-page="bySparePageIndex"  :page-size="bySparePageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="bySpareTtotalPage" :total="bySpareTotalNumber"></el-pagination>
            </el-tab-pane>
        </el-tabs>
        <!-- 按计划汇总 点击计划总数量查看汇总计划的明细信息 明细弹窗 -->
        <el-dialog title="汇总计划的明细信息" :visible.sync="planQuantityVisible" size="large" :lock-scroll="false">
            <el-table :data="detailsData" border style="width: 100%">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                <el-table-column property="planCode" label="计划编号" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="source" label="计划来源" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="planCategory" label="计划分类" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="materialCode" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="standard" label="规格" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="unit" label="计量单位" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="quantity" label="计划数量" header-align="center"></el-table-column>
                <el-table-column property="price" label="单价" header-align="center" align="right"></el-table-column>
                <el-table-column property="amount" label="计划总金额" header-align="center" align="right"></el-table-column>
                <el-table-column property="deliveryTimeExpectation" label="期望到货日期" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="remark" label="备注" header-align="center" show-overflow-tooltip></el-table-column>
            </el-table>
        </el-dialog>
        <!-- 按计划、备件汇总 点击已采购数量查看PO明细 明细弹窗 -->
        <el-dialog title="PO明细" :visible.sync="quantityPurchasedVisible" size="large" :lock-scroll="false">
            <el-table :data="detailsData1" border style="width: 100%">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                <el-table-column property="planNo" label="订单编号" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="sapNo" label="SAP编号" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="materialCode" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="standard" label="规格" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="unit" label="计量单位" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="poQuantity" label="数量" header-align="center"></el-table-column>
            </el-table>
        </el-dialog>
        <!-- 按备件汇总 点击每行的计划数量查看汇总计划的明细信息
        <el-dialog title="明细" :visible.sync="checkTheDetailsVisible" size="large" :lock-scroll="false">
            <el-table :data="detailsData" border style="width: 100%">
                <el-table-column property="id" label="序" header-align="center" align="center" width="40"></el-table-column>
                <el-table-column property="planCode" label="计划编号" header-align="center"> </el-table-column>
                <el-table-column property="source" label="计划来源" header-align="center"> </el-table-column>
                <el-table-column property="planCategory" label="计划分类" header-align="center"> </el-table-column>
                <el-table-column property="materialCode" label="备件编号" header-align="center"></el-table-column>
                <el-table-column property="materialName" label="备件名称" header-align="center"></el-table-column>
                <el-table-column property="standard" label="规格" header-align="center"> </el-table-column>
                <el-table-column property="unit" label="计量单位" header-align="center"> </el-table-column>
                <el-table-column property="quantity" label="计划数量" header-align="center"></el-table-column>
                <el-table-column property="price" label="单价" header-align="center" align="right"> </el-table-column>
                <el-table-column property="amount" label="计划总金额" header-align="center" align="right"> </el-table-column>
                <el-table-column property="deliveryTimeExpectation" label="期望到货日期" header-align="center"></el-table-column>
                <el-table-column property="remark" label="备注" header-align="center"></el-table-column>
            </el-table>
        </el-dialog>-->
    </div>
</template>
<script>
    export default  {
        data() {
            return {
                queryForm: {
                    no: '',
                    createTimeStart:'',
                    createTimeEnd:'',
                    creatorName:'',
                    show:true,
                    materialCode:'',
                    materialName:'',
                    legalPersonName: '',
                    legalPersonId: ''
                },
                legalPersonLists: [],
                confirmStatus: [],
                materialConfirmStatus: [],
                activeName: 'first',
                loading: false,
                loading2:false,
                // 按计划汇总
                formInline: {
                    legalPersonMessage: "",
                    spareCode: "",
                    spareName: "",
                    status: "",
                    quotationDeadline: ""
                },
                byPlanTableData: [],    //按计划汇总查询  列表
                isPaging1:false,
                byPlanPageIndex: 1,
                byPlanPageSize: 10,
                byPlanTtotalPage: 2,
                byPlanTotalNumber: 18,


                queryBySpareTable: [],  // 按备件汇总查询 列表
                isPaging2: false,
                bySparePageIndex: 1,
                bySparePageSize: 10,
                bySpareTotalPage: 2,
                bySpareTotalNumber: 18,
                planQuantityVisible: false,    // 按计划汇总 点击计划总数量查看汇总计划的明细信息
                quantityPurchasedVisible:false,   //按计划、备件汇总 点击已采购数量查看PO明细

                // checkTheDetailsVisible:false,    // 按备件汇总 点击每行的计划数量查看汇总计划的明细信息
                detailsData: [],    //计划总数量明细
                detailsData1: [],  //已采购数量明细
                approvalForm: {
                    textarea: ""
                },
                nowQuotationNumber: '',
                nowSpareCoding: '',
                //权限
                powerFlag:false,
                powerFlag1:false,
                powerFlag2:false,
                powerFlag3:false,
                //查询禁用
                selectDisabled:false,
                select2Disabled:false
            };
        },
        computed:{
            powerData(){
                return this.$store.state.powerData;
            }
        },
        watch:{
            powerData(){
                var _this=this;
                for(var i=0;i<_this.powerData.length;i++){
                    if(_this.powerData[i]=="ROLE_security_planDistribution_replace"){
                        //计划分配替换权限
                        _this.powerFlag1=true;
                    }
                    if(_this.powerData[i]=="ROLE_security_planDistribution_createPO"){
                        //创建po权限
                        _this.powerFlag2=true;
                    }
                    if(_this.powerData[i]=="ROLE_security_planDistribution_changeSupplier"){
                        //计划分配更改供应商权限
                        _this.powerFlag3=true;
                    }
                }
            }
        },
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'PlannedDistribution');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            _this.showLegalPerson();   //法人名称
            _this.planSCDropDownValue();
            _this.queryByPlan();   //默认是按计划查询
            //判断权限
            for(var i=0;i<_this.powerData.length;i++){
                if(_this.powerData[i]=="ROLE_security_planDistribution_replace"){
                    //计划分配替换权限
                    _this.powerFlag1=true;
                }
                if(_this.powerData[i]=="ROLE_security_planDistribution_createPO"){
                    //创建po权限
                    _this.powerFlag2=true;
                }
                if(_this.powerData[i]=="ROLE_security_planDistribution_changeSupplier"){
                    //计划分配更改供应商权限
                    _this.powerFlag3=true;
                }
            }
            if(_this.powerFlag1 && _this.powerFlag2 && _this.powerFlag3){
                _this.powerFlag=true;
            }
        },
        methods: {
            // 按计划汇总  按备件汇总 tab
            handleClick(tab, event) {
                var _this=this;                
                _this.queryForm.no="";
                _this.queryForm.createTimeStart="";
                _this.queryForm.createTimeEnd="";
                _this.queryForm.creatorName="";
                _this.queryForm.show=true;
                _this.queryForm.materialCode="";
                _this.queryForm.materialName="";
                _this.queryForm.legalPersonName="";
                _this.queryForm.legalPersonId="";
                _this.showLegalPerson();   //法人名称
               if (_this.activeName == 'first') {
                    _this.queryByPlan();
                } else {
                    _this.queryBySpare(); 
                }
            },
            // 选择汇总开始日期
            selectedCreateTimeStart(val){
                var _this=this;
                _this.queryForm.createTimeStart = val;
            },
            // 选择汇总结束日期
            selectedCreateTimeEnd(val){
                var _this=this;
                _this.queryForm.createTimeEnd = val;
            },
            //显示法人名称下拉框
            showLegalPerson() {
                var _this = this;
                $.ajax({
                    type: 'GET',
                    url: _this.procurement_service + "legalPerson/ofCurrentUser",
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.legalPersonLists = data.data;
                            if(_this.legalPersonLists.length == 1){
                                _this.queryForm.legalPersonName=_this.legalPersonLists[0].legalPersonName;
                                _this.queryForm.legalPersonId=_this.legalPersonLists[0].id;
                            }
                            // setTimeout(function(){
                            //     _this.queryByPlan();   //默认是按计划查询
                            // },0);
                        } else {
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },

            //下拉列表选择报价单确认状态
            planSCDropDownValue(){
                var _this = this;
                var tmp = ["confirmStatus","materialConfirmStatus"];
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service + 'procurement/getPullDownList',
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.confirmStatus = data.data.confirmStatus;
                            _this.materialConfirmStatus = data.data.materialConfirmStatus;
                        } else {
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 下拉列表选择法人名称
            selectLegalPersonName(){
                var _this = this;
                for (var i = 0; i < _this.legalPersonLists.length; i++) {
                    if (_this.queryForm.legalPersonName == _this.legalPersonLists[0].legalPersonName) {
                        _this.queryForm.legalPersonId = _this.legalPersonLists[0].id;
                    }
                }
            },
            // 按计划汇总查询
            queryByPlan(){
                var _this = this;
                _this.loading = true;
                var tmp = {
                    legalPersonId:_this.queryForm.legalPersonId,
                    no:_this.queryForm.no,
                    createTimeStart:_this.queryForm.createTimeStart,
                    createTimeEnd:_this.queryForm.createTimeEnd,
                    creatorName:_this.queryForm.creatorName,
                    show:_this.queryForm.show,
                    pageIndex: _this.byPlanPageIndex,
                    pageSize: _this.byPlanPageSize,
                };
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service + "planAggregation/queryPage",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            _this.loading = false;
                            _this.byPlanTableData = data.data.dataList;
                            //计算未采购数量
                            for(var i=0;i<_this.byPlanTableData.length;i++){
                                if(_this.byPlanTableData[i].amount == "" || _this.byPlanTableData[i].amount == null){
                                    _this.byPlanTableData[i].amount=0;
                                }
                                _this.byPlanTableData[i].quantityNotPurchased=_this.byPlanTableData[i].totalQuantity - _this.byPlanTableData[i].amount;
                            }
                            _this.isPaging1=true;
                            _this.byPlanTtotalPage=data.data.totalPage;
                            _this.byPlanTotalNumber=data.data.totalNumber;
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.selectDisabled=false;    
                    }
                });
            },
            //  按计划汇总 分页
            handleByPlanSizeChange(val){
                var _this=this;
                _this.byPlanPageSize=val;
                _this.queryByPlan();
            },
            // 按计划汇总    点击页码分页查询点击事件
            handleByPlanCurrentChange(val){
                var _this=this;
                _this.byPlanPageIndex=val;
                _this.queryByPlan();
            },
            // 按计划、备件汇总 点击计划总数量查看汇总计划的明细信息
            planQuantity(index, row){
                var _this = this;
                var tmp;
                _this.planQuantityVisible = true;
                if(_this.activeName == 'first'){
                    tmp = {planAggregationId: row.id};
                }else{
                    tmp = {planAggregationItemId:row.id};
                }
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service + "planAggregation/queryPlanItemsByAggregationItemId",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            var arr=data.data;
                            //单价保留八位小数，总金额保留两位
                            for(var i=0;i<arr.length;i++){
                                arr[i].price=arr[i].price.toFixed(8);
                                arr[i].amount=arr[i].amount.toFixed(2);
                            }
                            _this.detailsData = arr;
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            // 按计划汇总  已采购数量
            byPlanQuantityPurchased(index, row){
                var _this = this;
                _this.quantityPurchasedVisible = true;
                var tmp = {
                    planAggregationId: row.id
                };
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service + "planAggregationProcurement/queryByPlanAggregationId",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.detailsData1 = data.data;
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            // 按备件汇总查询
            queryBySpare(){
                var _this = this;
                _this.loading2 = true;
                var tmp = {
                    legalPersonId:_this.queryForm.legalPersonId,
                    no:_this.queryForm.no,
                    createTimeStart:_this.queryForm.createTimeStart,
                    createTimeEnd:_this.queryForm.createTimeEnd,
                    creatorName:_this.queryForm.creatorName,
                    show:_this.queryForm.show,
                    materialCode:_this.queryForm.materialCode,
                    materialName:_this.queryForm.materialName,
                    pageIndex: _this.bySparePageIndex,
                    pageSize: _this.bySparePageSize,
                };
                _this.select2Disabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service + "planAggregation/item/queryPage",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.loading2 = false;
                            _this.queryBySpareTable = data.data.dataList;
                            //计算未采购数量
                            for(var i=0;i<_this.queryBySpareTable.length;i++){
                                if(_this.queryBySpareTable[i].amount == "" || _this.queryBySpareTable[i].amount == null){
                                    _this.queryBySpareTable[i].amount=0;
                                }
                                _this.queryBySpareTable[i].quantityNotPurchased=_this.queryBySpareTable[i].quantity - _this.queryBySpareTable[i].amount;
                            }
                            _this.isPaging2=true;
                            _this.bySpareTtotalPage=data.data.totalPage;
                            _this.bySpareTotalNumber=data.data.totalNumber;
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.select2Disabled=false;    
                    }
                });
            },
            // 按备件汇总  已采购数量
            bySpareQuantityPurchased(index,row){
                var _this=this;
                _this.quantityPurchasedVisible = true;
                 var tmp = {
                    planAggregationItemId: row.id
                };
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service + "planAggregationProcurement/queryByPlanAggregationItemId",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.detailsData1 = data.data;
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
             //  按备件汇总 分页
            handleBySpareSizeChange(val){
                var _this=this;
                _this.bySparePageSize=val;
                _this.queryBySpare();
            },
            // 按备件汇总    点击页码分页查询点击事件
            handleBySpareCurrentChange(val){
                var _this=this;
                _this.bySparePageIndex=val;
                _this.queryBySpare();
            },
            
            

            // 备件报价确认按钮
            mterialAccess(index, row){
                var _this = this;
                _this.nowQuotationNumber = row.quotationNumber;
                _this.nowSpareCoding = row.spareCoding;
                console.log(row.confirmStatus)
            },

            // 报价单确认按钮
            quotationAccess(index, row){
                var _this = this;
                _this.nowQuotationNumber = row.quotationNumber;
            },
            // 开制PO
            openSystemPO(row){
                var _this=this;
                _this.$router.push({path:"/SummaryDetails",query:{planAggregationItemId:row.id,no:row.no}});
            },
            // //=================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },

            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }

        }
    };
</script>